package com.uuah.server.util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.jar.Manifest;

import com.uuah.config.UuahManifest;
import com.uuah.server.api.IUuahContext;
import com.uuah.server.config.i18n.ServerMessages;
import com.uuah.utils.StringUtils;

public class ServerStartupSplashMsg extends SplashMsg {
	protected void doHeader(IUuahContext context) {
		String notset = ServerMessages.notSet().getMessage();

		Manifest mf = UuahManifest.getManifest();
		Map att = mf.getMainAttributes();
		if (att.values().size() > 0) {
			header.add(StringUtils.defaultString(UuahManifest
					.getProductDescription(), notset));
			header.add(ServerMessages.version().getMessage()
					+ " Build: "
					+ StringUtils.defaultString(UuahManifest.getBuildNumber(),
							notset));

			header.add(StringUtils.defaultString(UuahManifest.getVendorName(),
					notset));
			header.add(StringUtils.defaultString(UuahManifest
					.getProductMoreInfo(), notset));
		} else {
			header.add(ServerMessages.versionNotSet().getMessage());
		}
		header.add(" ");

		header.add("Server ID: " + context.getConfiguration().getId());

		header.add("JDK: " + System.getProperty("java.version") + " ("
				+ System.getProperty("java.vm.info") + ")");
		header.add("OS Encoding: " + System.getProperty("file.encoding")
				+ ", Uuah App Server Encoding:"
				+ context.getConfiguration().getDefaultEncoding());
		String patch = System.getProperty("sun.os.patch.level", null);
		header.add("OS: "
				+ System.getProperty("os.name")
				+ (patch != null && !"unknown".equalsIgnoreCase(patch) ? " - "
						+ patch : "") + " (" + System.getProperty("os.version")
				+ ", " + System.getProperty("os.arch") + ")");
		try {
			InetAddress host = InetAddress.getLocalHost();
			header.add("Host: " + host.getHostName() + " ("
					+ host.getHostAddress() + ")");
		} catch (UnknownHostException e) {
			// ignore
		}
		if (context.getStartDate() > 0) {
			header.add(ServerMessages.serverStartedAt(context.getStartDate())
					.getMessage());
		}
		header.add(" ");
	}

	protected void doFooter(IUuahContext context) {
		if (!body.isEmpty()) {
			footer.add(" ");
		}
	}
}
